package com.egg.ylt.presenter.impl;

import com.egg.ylt.Utils.API;
import com.egg.ylt.pojo.BindEquipmentEntity;
import com.egg.ylt.presenter.IScanCodePresenter;
import com.egg.ylt.view.IScanCodeView;
import com.yonyou.framework.library.bean.ErrorBean;
import com.yonyou.framework.library.common.CommonUtils;
import com.yonyou.framework.library.mvp.impl.BasePresenter;
import com.yonyou.framework.library.net.ReqCallBack;
import com.yonyou.framework.library.net.RequestManager;

import java.util.HashMap;

public class ScanCodePresenterImpl extends BasePresenter<IScanCodeView> implements IScanCodePresenter {
    @Override
    public void setBind(String token, String equipCode, String memberCompanyId, String deviceCode) {
        mView.showDialogLoading("数据加载中");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("token", token);
        hashMap.put("equipCode", equipCode);
        hashMap.put("memberCompanyId", memberCompanyId);
        hashMap.put("deviceCode", deviceCode);
        RequestManager.getInstance().requestPostByAsyn(API.POST_BIND_EQUIPMENT, hashMap, new ReqCallBack<BindEquipmentEntity>() {

            @Override
            public void onReqSuccess(BindEquipmentEntity result) {
                mView.dismissDialogLoading();
                mView.setBindFacility(result);
            }

            @Override
            public void onFailure(String result) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, result, false);
            }

            @Override
            public void onReqFailed(ErrorBean error) {
                mView.dismissDialogLoading();
                mView.getScanFailure();
                CommonUtils.makeEventToast(mContext, error.getMsg(), false);
            }
        });
    }
}
